package cn.gemiman.daoyi.module.netty.server.mqtt.options;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;
import java.util.Calendar;
import java.util.function.Function;

/**
 * 设备连接上后保存相应的session，统一由DeviceSessionManager管理
 *
 * @author Gemiman
 * @date 2021/10/5 20:22
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
public class ClientSession implements Serializable {
    /**
     * mqtt连接的用户名
     */
    private String username;
    /**
     * mqtt连接的密码
     */
    private byte[] password;
    /**
     * mqtt连接的ip
     */
    private String ip;
    /**
     * 设备唯一标识
     */
    private String uuid;
    /**
     * 设备对应的通信通道id
     */
    private String channelId;

    /**
     * 给设备发送消息的回调函数
     */
    private Function<CustomMqttPublishMessage, Boolean> publisher;

    /**
     * 设备最后刷新时间，也就是最后一次给paas发送数据的时间
     */
    private Calendar refreshTime;
    /**
     * 一些额外的数据，用于扩展
     */
    private Object data;

    public ClientSession(String ip, String uuid, String channelId, Function<CustomMqttPublishMessage, Boolean> publisher, String username, byte[] password) {
        this.uuid = uuid;
        this.ip = ip;
        this.channelId = channelId;
        this.publisher = publisher;
        this.username = username;
        this.password = password;
    }
}
